package com.zmn.oms.third.haobai;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.zmn.oms.common.utils.HttpUtil;
import com.zmn.oms.third.haobai.dto.HaobaiResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;

import java.util.Map;

/**
 * @author: huangyifeng
 * @description:
 * @create: 2020-03-09 17:32
 **/
@Slf4j
public class HaobaiApiInvoker {

    public static HaobaiResultDTO sendingNotice(Map<String, Object> params){
        HaobaiResultDTO result = new HaobaiResultDTO();

        try {
            String jsonData = JSON.toJSONString(params);
            String url = HaobaiConsts.HAOBAI_REQUEST_URL;

            log.info("[号百-便民平台] api请求：url=[{}], request=[{}]", url, jsonData);
            String response = HttpUtil.httpPost(url, jsonData);
            log.info("[号百-便民平台] api响应：response=[{}]", response);

            result = JSON.parseObject(response, HaobaiResultDTO.class);

        } catch (Exception e) {
            log.error("[号百-便民平台] 请求号百网络异常：[{}]", e.getMessage());
            result.setCode("1");
            result.setErrors("网络异常");
        }
        return result;
    }
}
